(function ($) {
    $(function () {
      var
          oPhone = $ ('.phone>.phone-ewm'),
          oPhoneImg = $ ('.phone-img'),
          oLiMan = $ ('.li-man'),
          oMan = $ ('.man'),
          oLiWomen = $ ('.li-women'),
          oWomen = $ ('.women'),
          oLiMeiZ = $ ('.li-MeiZ'),
          oMeiZ = $ ('.MeiZ'),
          oLijaJu = $ ('.li-jaJu'),
          ojaJu = $ ('.jaJu'),
          oLiChild = $ ('.li-child'),
          oChild = $ ('.child'),
          oliAoLai = $ ('.li-old-AoLai'),
          old_AoLai = $ ('.old-AoLai'),
          oNavRight = $ ('.nav-right'),
          oGoodBox = $ ('.goods-box'),
          oXX = $ ('.goods-box>a');

        setHeight(oPhone,oPhoneImg,132);
        setHeight(oNavRight,oGoodBox,70);
        oXX.click(function(){
            oGoodBox.stop(true).animate({height:0},50)
        });

        nav(oLiMan,oMan);
        nav(oLiWomen,oWomen);
        nav(oLiMeiZ,oMeiZ);
        nav(oLijaJu,ojaJu);
        nav(oLiChild,oChild);
        nav(oliAoLai,old_AoLai);

      var
          oLi1 = $('.li1'),
          oLi2 = $('.li2'),
          oLi3 = $('.li3'),
          oLi4 = $('.li4'),
          oLi5 = $('.li5'),
          oLi6=  $('.li6');

        oLi1.mouseenter(function(){
            oLi1.css({backgroundPosition:'-150px -262px'})
        }).mouseleave(function(){
            oLi1.css({backgroundPosition:'-150px -144px'})
        });
        oLi2.mouseenter(function(){
            oLi2.css({backgroundPosition:'-545px 11px'})
        }).mouseleave(function(){
            oLi2.css({backgroundPosition:'-545px -100px'})
        });
        oLi3.mouseenter(function(){
            oLi3.css({backgroundPosition:'-306px -229px'})
        }).mouseleave(function(){
            oLi3.css({backgroundPosition:'-155px -382px'})
        })
        oLi4.mouseenter(function(){
            oLi4.css({backgroundPosition:'-420px -102px'})
        }).mouseleave(function(){
            oLi4.css({backgroundPosition:'-420px 10px'})
        })
        oLi5.mouseenter(function(){
            oLi5.css({backgroundPosition:'-305px -453px'})
        }).mouseleave(function(){
            oLi5.css({backgroundPosition:'-305px -340px'})
        });

        oLi6.mouseenter(function(){
            oLi6.css({backgroundPosition:'-305px 7px'})
        }).mouseleave(function(){
            oLi6.css({backgroundPosition:'-305px -110px'})
        });

        var
            oRightDiv = ('.right-div'),
            oChuXian  = $('.chuXian'),
            ONav = $ ('#nav');
        oChuXian.click(function(){
            document.body.scrollTop=0;
            document.documentElement.scrollTop=0;
        });

        //导航条position:fixed
        $(window).scroll(function(){
            var scrollTop = document.body.scrollTop||document.documentElement.scrollTop;
            if (scrollTop>110){
                ONav.css({position: 'fixed',left:0,top:0})
            }
            if (scrollTop<110){
                ONav.css({position: 'relative',left:0,top:0})
            }
            if(scrollTop>500){
                oChuXian.css({display:'block'})
            }
            if(scrollTop<500){
                oChuXian.css({display:'none'})
            }
        });
        var
            oOnlineLi = $('.head-top .online'),
            oOnline = $('#online'),
            oOnlineSpan = $('#online .span1');

        oOnlineLi.click(function(){
            oOnline.css({display:'block'});
        });
     /*   oOnlineSpan.keyup(function(evt){
            var oldX =
        })*/


        //窗口拖动

        var
            subNavRightOn  = $('.subNav-right .online'),
            oOnline        = $('#online'),
            oTx            = $ ('#tx'),
            oOnlineMaddleUi = $('.online-maddle ul'),
            oButton1        = $('#button'),
            oOnlineTop      = $('.online-top'),
            oOnlineMaddle   = $('.online-maddle ul'),
            oSa1            = $('.online-top .sa1'),
            oSa2            = $('.online-top .sa2'),
            oSa3            = $('.online-top .sa3');
        oButton1.click(function(){
            oOnlineMaddleUi.append('<li><em></em><span>'+oTx.val()+'</span></li>');
            oTx.val('');
        });
        oSa1.click(function(){
            oOnline.css({height:42});
            oOnline.css({right:0,top:0});
        });
        oSa2.click(function(){
            oOnline.css({height:625});
            oOnlineMaddle.css({height:400});
        });
        oSa3.click(function(){
            oOnline.css({display:'none'})
        });

        subNavRightOn.click(function(){
            oOnline.css({display:'block'})
        });
        var xMax =document.documentElement.clientWidth-oOnline.outerWidth();
        var yMax =document.documentElement.clientHeight-oOnline.outerHeight();
        oOnlineTop.mousedown(function(evt){
            var event = evt || window.event;
            var x = event.clientX -oOnlineTop.offset().left;
            var y = event.clientY -oOnlineTop.offset().top;
            $(document).mousemove(function(evt1){
                var event1 = evt1 || window.event;
                var left = event1.clientX - x;
                var top1 = event1.clientY - y;
                if(left<0){
                    left=0
                }
                if(left>xMax){
                    left=xMax
                }
                if(top1<0){
                    top1=0
                }
                if(top1>yMax){
                    top1=yMax
                }
                oOnline.css({left:left,top:top1});
                oOnlineTop.mouseup(function(){
                    $(document).mousemove(function(){
                        oOnline.css({left:left,top:top1});
                    })
                })
           })
        });
        $(window).scroll(function(){
            oOnline.css({position:'fixed'})
        });






        //封装导航显示隐藏函数
        function nav(obj1,obj2){
            obj1.mouseenter(function(){
                obj2.css({display:'block'})
            }).mouseleave(function(){
                obj2.css({display:'none'})
            })
        }
        //封装导航高度显示函数
        function setHeight(obj1,obj2,height){
            obj1.mouseenter(function(){
                obj2.stop(true).animate({height:height},50)
            }).mouseleave(function(){
                obj2.stop(true).animate({height:0},50)
            });
        }
    });
})(jQuery);